import { bindActionCreators, createSlice } from '@reduxjs/toolkit'
import { ITestState } from '../reduxType'

// // 设置类型
// export interface testState {
//   value: number;
//   ip: object
// }
// // 设置初始化state
// const initialState: testState = {
//   value: 1,
//   ip:{}
// };

const initialState: ITestState = {
  startDate: '',
  endDate: '',
}
const testSlice = createSlice({
  name: 'test',
  initialState,
  reducers: {
    startDate(state, { payload }) {
      return (state.startDate = payload)
    },
    endDate(state, { payload }) {
      return (state.endDate = payload)
    },
  },
})
// 导出 actions
export const { startDate, endDate } = testSlice.actions
export const datapickerActions = testSlice.actions
// export const { increment, decrement } = counterSlice.actions
// export const counterAction = counterSlice.actions

// 内置了 thunk 插件, 可以直接处理异步请求
export const asyncEndDate = (payload: string) => (dispatch: any) => {
  setTimeout(() => dispatch(endDate(payload)), 2000)
}
// export const asyncDecrement = (payload: number) => (dispatch: any) => {
//   setTimeout(() => dispatch(decrement(payload)), 2000)
// }

// 导出 reducer, 在创建 store 时使用到
export default testSlice.reducer
